import Foundation

let session = URLSession.shared
let url = URL(string: "https://api.nytimes.com/svc/search/v2/articlesearch.json?api-key=YOUR_API_KEY&fq=section_name:(\"your_section_id\")")!

var request = URLRequest(url: url)
request.httpMethod = "GET"

let task = session.dataTask(with: request) { data, response, error in
    guard let data = data,
          let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
          let docs = json["response"] as? [String: Any],
          let articles = docs["docs"] as? [[String: Any]] else {
        print("Error fetching or parsing data.")
        return
    }

    for article in articles {
        if let title = article["headline"] as? [String: String], let mainTitle = title["main"] {
            print(mainTitle)
        }
    }
}

task.resume()